<?php


$dsn="mysql:Server=127.0.0.1;dbname=blog";
$db= new PDO($dsn, "root", "123456");
$db ->exec("set names utf8mb4");

$addTime =time();
$updateTime =$addTime;

$sql ="insert into admin (admin_email, admin_name, admin_password, update_time, add_time)
        values ('$adminEmail', '$adminName', '$adminPassword', '$updateTime', '$addTime')";
$result =$db->exec($sql);
var_dump($result);


//// 检测邮箱是否存在了。
$sql = "select * from admin where admin_email='$adminEmail'";
$statement = $db->query($sql);
if ($statement->fetch()) {
    echo $adminEmail . ' 邮箱已经存在，请输入另外的邮箱。';
    echo '<a href="index.php?c=admin_list">返回列表页面</a>';
//    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}

if (mb_strlen($adminName) < 2 || mb_strlen($adminName) > 50) {
    echo '姓名限制2~50个字';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
// 10~100
if (mb_strlen($adminEmail) < 1 || mb_strlen($adminEmail) > 100) {
    echo '邮箱限制1~100个字';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
// 10~8000
if (mb_strlen($adminPassword) < 6 || mb_strlen($adminPassword) > 50) {
    echo '密码长度6~20。';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}
if ($adminPassword !== $adminPassword2) {
    echo '两次密码输入不一致。';
    echo '<a href="javascript:void(0)" onclick="history.back();">返回上一页</a>';
    exit();
}